<?php
	include_once("core/functions.php");
	//$showmonth = date('n');
	//$showyear = date('Y');
	
	$showmonth = $_POST['showmonth'];
	$showyear = $_POST['showyear'];
	$showmonth = preg_replace('#[^0-9]#i', '', $showmonth);
	$showyear = preg_replace('#[^0-9]#i','',$showyear);

	$day_count = cal_days_in_month(CAL_GREGORIAN, $showmonth,$showyear);
	$pre_days = date('w',mktime(0,0,0,$showmonth,1,$showyear));
	$post_days = (6 - (date('w',mktime(0,0,0,$showmonth,$day_count,$showyear))));
	$current_day = date('j');
	$current_month = date('n');

		//Pre days filler
		if($pre_days != 0)
		{
			for($i=1;$i<=$pre_days;$i++)
			{
				echo '<div class="non_cal_day"></div>';
			}
		}
		//current ller
		for($i=1;$i<=$day_count;$i++)
		{	
			echo '<div class="cal_day">';
				echo '<div class="day_heading">';
					if($current_month == $showmonth && $current_day == $i)
					{
						echo '<b>'.$i.'</b>';
					}
					else
					{
						echo $i;
					}
                echo '</div>';
                $date = $showyear."-".$showmonth."-".$i;
                if(Event::checkForEvents($date))
                {
                    echo '<br/><br/>';
                    echo '<div class="showEvents"><a href="viewEvent.php?startDate='.$date.'">Show Events</a></div>';			
                }
			echo '</div>';
		}

		//post days filler
		if($post_days!=0)
		{
			for($i=1;$i<=$post_days;$i++)
			{
				echo '<div class="non_cal_day"></div>';
			}
		}
?>